home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-09-25 | 4.5 KB | 139 lines | [TEXT/MPS ] |
- PROGRAM Tips1;
-
- USES Memtypes,QuickDraw,OSIntf,ToolIntf,PackIntf,MacPrint;
-
- CONST
- PostScriptBegin = 190;
- PostScriptEnd = 191;
- PostScriptHandle = 192;
- PostScriptBeginNoSave = 196;
-
- PROCEDURE SetFont(fontName: Str255; fontSize: INTEGER; fontStyle: Style);
- VAR
- theFontID: INTEGER;
- thePenLoc: Point;
- BEGIN
- GetFNum(fontName, theFontID); (* Get the font ID. *)
- TextFont(theFontID); (* Set it. *)
- TextSize(fontSize); (* Set the size... *)
- TextFace(fontStyle); (* ...and the style. *)
- GetPen(thePenLoc); (* Save the current pen position. *)
- DrawChar(' '); (* Draw a space so the font gets downloaded.*)
- MoveTo(thePenLoc.h, thePenLoc.v); (* Restore the original pen position. *)
- END;
-
- PROCEDURE SendPostScript(theComment: Str255);
- VAR
- PSCommand : Str255;
- CommandHdl : Handle;
- CRString : Str255;
- theError : OSErr;
- BEGIN
- CRString := ' ';
- CRString[1] := CHR(13);
- PSCommand := theComment;
- PSCommand := CONCAT(PSCommand, CRString);
- theError := PtrToHand(POINTER(ORD(@PSCommand) + 1), CommandHdl,
- LENGTH(PSCommand));
- if theError <> noErr THEN BEGIN
- (* Handle the error! *)
- END;
- PicComment(PostScriptHandle, LENGTH(PSCommand), CommandHdl);
- DisposHandle(CommandHdl);
- END;
-
- PROCEDURE DrawStuff(theWorld : Rect);
- { Draw whatever you want here. Make sure it fits in the world rectangle. }
- BEGIN
- (* Set the font using our new SetFont routine. This will set the font *)
- (* for both the Quickdraw and PostScript worlds. *)
- SetFont('Times', 14, [bold]);
- PicComment(PostScriptBegin, 0, NIL);
- (********************************************)
- (*** Quickdraw representation of graphic. ***)
- (********************************************)
- (* These calls are only executed by Quickdraw (i.e. non-PostScript) *)
- (* devices. *)
- MoveTo(50, 50);
- DrawString('This is some Quickdraw text (Times, 14, bold).');
- MoveTo(100, 100);
- LineTo(300, 300);
-
- (*********************************************)
- (*** PostScript representation of graphic. ***)
- (*********************************************)
- (* These calls will only be executed by PostScript devices. *)
- SendPostScript('50 50 moveto (This is some PostScript text (Times, 14, bold).) show');
- SendPostScript('100 100 moveto 300 300 lineto stroke');
- PicComment(PostScriptEnd, 0, NIL);
-
- (* Now illustrate the use of the PostScriptBeginNoSave PicComment. *)
- PicComment(PostScriptBeginNoSave, 0, NIL);
- PenPat(ltGray);
- SendPostScript('.10 setgray');
- PicComment(PostScriptEnd, 0, NIL);
-
- (* Draw a light gray line using Quickdraw. *)
- MoveTo(50, 400);
- Line(100, 100);
-
- PicComment(PostScriptBeginNoSave, 0, NIL);
- PenPat(black);
- SendPostScript('1.0 setgray');
- PicComment(PostScriptEnd, 0, NIL);
- END;
-
-
- PROCEDURE PrintStuff;
- VAR
- thePrRec : THPrint;
- thePrPort : TPPrPort;
- theStatus : TPrStatus;
- oldPort : GrafPtr;
- theError : OSErr;
- theVers: INTEGER;
-
- BEGIN
- GetPort(oldPort);
- thePrRec := THPrint(NewHandle(SIZEOF(TPrint)));
-
- PrOpen;
- theVers := PrDrvrVers;
- IF PrError = noErr THEN BEGIN
- PrintDefault(thePrRec);
- IF NOT PrStlDialog(thePrRec) THEN
- ExitToShell;
- IF NOT PrJobDialog(thePrRec) THEN
- ExitToShell;
- thePrPort := PrOpenDoc(thePrRec, NIL, NIL);
- IF PrError = noErr THEN BEGIN
- PrOpenPage(thePrPort, NIL);
- IF PrError = noErr THEN BEGIN
-
- DrawStuff(thePrRec^^.prInfo.rPage);
-
- END;
- PrClosePage(thePrPort)
- END;
- PrCloseDoc(thePrPort);
- IF (thePrRec^^.prJob.bJDocLoop = bSpoolLoop) and (PrError = noErr) THEN
- PrPicFile(thePrRec, NIL, NIL, NIL, theStatus);
- END;
- PrClose;
-
- SetPort(oldPort);
- END;
-
- BEGIN
- InitGraf(@thePort); {initialize QuickDraw}
- InitFonts; {initialize Font Manager}
- FlushEvents(everyEvent, 0); {call OS Event Mgr to discard any previous events}
- InitWindows; {initialize Window Manager}
- InitMenus; {initialize Menu Manager}
- TEInit; {initialize TextEdit}
- InitDialogs(NIL); {initialize Dialog Manager}
- InitCursor; {call QuickDraw to make cursor (pointer) an arrow}
-
- PrintStuff;
- END.
-